﻿<template>
  <a-modal
    title="新增运营日报"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-form-item label="上级ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入上级ID" v-decorator="['parentId']" />
        </a-form-item>
        <a-form-item label="上级编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入上级编码" v-decorator="['parentDataCode']" />
        </a-form-item>
        <a-form-item label="上级数据名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入上级数据名称" v-decorator="['parentDataName']" />
        </a-form-item>
        <a-form-item label="编码" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入编码" v-decorator="['dataCode']" />
        </a-form-item>
        <a-form-item label="数据名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入数据名称" v-decorator="['dataName']" />
        </a-form-item>
        <a-form-item label="" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入" v-decorator="['dayNum']" />
        </a-form-item>
        <a-form-item label="收入金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入收入金额" v-decorator="['dataAmount']" />
        </a-form-item>
        <a-form-item label="当月累计数量" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入当月累计数量" v-decorator="['monthNum']" />
        </a-form-item>
        <a-form-item label="当月累计金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入当月累计金额" v-decorator="['monthAmount']" />
        </a-form-item>
        <a-form-item label="充值金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入充值金额" v-decorator="['rechargeAmount']" />
        </a-form-item>
        <a-form-item label="续费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入续费金额" v-decorator="['reNewAmount']" />
        </a-form-item>
        <a-form-item label="退费金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入退费金额" v-decorator="['refundAmount']" />
        </a-form-item>
        <a-form-item label="合计金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入合计金额" v-decorator="['totalAmount']" />
        </a-form-item>
        <a-form-item label="日均数量" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入日均数量" v-decorator="['avgDayNum']" />
        </a-form-item>
        <a-form-item label="日均金额" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入日均金额" v-decorator="['avgDayAmount']" />
        </a-form-item>
        <a-form-item label="医院ID" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入医院ID" v-decorator="['hospitalId']" />
        </a-form-item>
        <a-form-item label="医院名称" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入医院名称" v-decorator="['hospitalName']" />
        </a-form-item>
        <a-form-item label="备注" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入备注" v-decorator="['remark']" />
        </a-form-item>
        <a-form-item label="预留1" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留1" v-decorator="['field01']" />
        </a-form-item>
        <a-form-item label="预留2" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留2" v-decorator="['field02']" />
        </a-form-item>
        <a-form-item label="预留3" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留3" v-decorator="['field03']" />
        </a-form-item>
        <a-form-item label="预留4" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留4" v-decorator="['field04']" />
        </a-form-item>
        <a-form-item label="预留5" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入预留5" v-decorator="['field05']" />
        </a-form-item>
        <a-form-item label="状态" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入状态" v-decorator="['status']" />
        </a-form-item>
        <a-form-item label="报表类型" :labelCol="labelCol" :wrapperCol="wrapperCol" has-feedback>
          <a-input placeholder="请输入报表类型" v-decorator="['type']" />
        </a-form-item>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import {
    DayReportAdd
  } from '@/api/modular/main/DayReportManage'

  export default {
    data () {
      return {
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 15 }
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      // 初始化方法
      add (record) {
        this.visible = true
      },
      /**
       * 提交表单
       */
      handleSubmit () {
        const { form: { validateFields } } = this
        this.confirmLoading = true
        validateFields((errors, values) => {
          if (!errors) {
            for (const key in values) {
              if (typeof (values[key]) === 'object') {
                values[key] = JSON.stringify(values[key])
              }
            }
            DayReportAdd(values).then((res) => {
              if (res.success) {
                this.$message.success('新增成功')
                this.confirmLoading = false
                this.$emit('ok', values)
                this.handleCancel()
              } else {
                this.$message.error('新增失败：' + JSON.stringify(res.message))
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel () {
        this.form.resetFields()
        this.visible = false
      }
    }
  }
</script>
